package mylab.usm.oauth2.client.controller;

import com.fujieid.jap.core.config.AuthenticateConfig;
import com.fujieid.jap.oauth2.OAuthConfig;
import com.fujieid.jap.oauth2.Oauth2EndpointMethodType;
import com.fujieid.jap.oauth2.Oauth2GrantType;
import com.fujieid.jap.oauth2.Oauth2ResponseType;
import mylab.usm.oauth2.client.config.AuthProperties;
import mylab.usm.oauth2.client.config.AuthStrategy;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 使用第三方OAuth2.0服务之授权码模式（最广泛使用的模式）
 * 需要依赖 jap-oauth2 模块
 */
@RestController
@RequestMapping("/oauth2/code")
public class OAuth2CodeController extends BaseOAuth2Controller {

    @Override
    protected AuthStrategy getAuthStrategy() {
        return AuthStrategy.oauth2_authorization_code;
    }

    @Override
    protected AuthenticateConfig getAuthenticateConfig(AuthProperties.Platform platform) {
        OAuthConfig config = (OAuthConfig) super.getAuthenticateConfig(platform);

        //授权码模式
        config
                .setGrantType(Oauth2GrantType.AUTHORIZATION_CODE)
                .setResponseType(Oauth2ResponseType.CODE)
                .setAccessTokenEndpointMethodType(Oauth2EndpointMethodType.GET)
                .setUserInfoEndpointMethodType(Oauth2EndpointMethodType.GET);

        return config;
    }
}
